<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>231. 2 的幂</title>
</head>

<body>

</body>

<script>
    /**
     * @param {number} n
     * @return {boolean}
     */
    var isPowerOfTwo = function (n) {
        if (n <= 0) {
            return false;
        }
        let num = 0;
        let arr = n.toString(2).split('');
        arr.forEach(item => {
            if (item == 1) {
                num++;
            }
        })
        return num == 1;
    };
    console.log(isPowerOfTwo(-8));
</script>

</html>